﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Data.SqlClient;
using System.Configuration;
using System.Globalization;
using System.Threading;
using ERPStudio;
using System.IO;
using System.Reflection;

namespace Fares
{
    class dscModule : ModuleClass
    {
        public dscModule(Int16 codUnit, String numeUnit,String theme):base(codUnit,numeUnit,theme)
        {
            workConnectionString = "ESRPConnectionString";
            ModuleName = "fares";
        }
        /// <summary>
        /// returneaza ID-ul intern pentru autorizare - 
        /// deriva din numele modului si este o cheie de control
        /// </summary>
        /// <returns></returns>
        override public String GetModuleID()
        {
            return "30";
        }


        /// <summary>
        /// incarca meniul acestui modul
        /// </summary>
        /// <param name="myMenu"></param>
        public void LoadMenu(ToolStripMenuItem mn, Form vForm, Guid appid, Guid userID)
        {
            base.LoadMenu(mn, (FrmMainMdi)vForm, appid, userID);
            InitStoredProcedure("Init_Fares");
        }

        public void Unitati_functionale(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.UnitatiFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this, false }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void TipuriDimensiuni(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.TipDimensiuneFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        
        public void Parteneri(object sender, EventArgs e)
        {

            SqlConnection wConn = StudioForm.DeschideConexiune(workConnectionString);
            Object ret = StudioForm.GetSetupValue("FaresSetup", "ParteneriProprii", CodUnitate, wConn);
            String val = String.Empty;
            if (ret != null && ret != DBNull.Value)
                val = ret.ToString();
            else
            {
                while (ret == null)
                {
                    MessageBox.Show("Modulul Parteneri nu a fost configurat. \nVa rugam sa-l configurati!",
                            "Eroare",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Hand);
                    FaresSetupFrm frmS = new FaresSetupFrm(this);
                    frmS.ShowDialog();
                    ret = StudioForm.GetSetupValue("FaresSetup", "ParteneriProprii", CodUnitate, wConn);
                }
            }

            Object retObj = StudioForm.GetSetupValue("FaresSetup", "ParteneriProprii", CodUnitate, wConn);
            Boolean partProp = false; 
            if (retObj != null && retObj != DBNull.Value)
                partProp = Convert.ToBoolean(retObj);
            StudioForm.InchideConexiune(wConn);
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;
            String numeClasa = "ERPForms.PartenerFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmCard newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] { this, partProp }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmCard;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void Banci(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.BanciFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }
        public void Regimuri_Fiscale(object sender, EventArgs e)
        {
            RegimuriFiscaleFrm frm = new RegimuriFiscaleFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void NoteContabile(object sender, EventArgs e)
        {
            NoteContabileFrm frm = new NoteContabileFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }
        
        public void Trasee(object sender, EventArgs e)
        {
            //TraseeFrm frm = new TraseeFrm(this);
            //frm.MdiParent = mdiForm;
            //frm.Show();
        }

        public void ExportDeclaratii(object sender, EventArgs e)
        {
            ExportDeclaratiiFrm frm = new ExportDeclaratiiFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Incasari_Plati(object sender, EventArgs e)
        {
            PlatiFrm frm = new PlatiFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

	

	
        public void Documente_intrare(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,true);
            frm.Text = "Documente intrare";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_intrare_factura(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,true,0);
            frm.Text = "Documente intrare";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_intrare_bon_fiscal(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,true,10);
            frm.Text = "Documente intrare";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_intrare_comanda(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,true,12);
            frm.Text = "Documente intrare";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_intrare_receptie(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,true,15);
            frm.Text = "Documente intrare";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_iesire(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,false);
            frm.Text = "Documente iesire";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_iesire_factura(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,false,1);
            frm.Text = "Documente iesire";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_iesire_bon_fiscal(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,false,11);
            frm.Text = "Documente iesire";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_iesire_comanda(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,false,9);
            frm.Text = "Documente iesire";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_iesire_bon_consum(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,false,13);
            frm.Text = "Documente iesire";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Documente_iesire_aviz_expeditie(object sender, EventArgs e)
        {
            DocumenteFrm frm = new DocumenteFrm(this,false,14);
            frm.Text = "Documente iesire";
            frm.MdiParent = mdiForm;
            frm.Show();
        }


        public void Locatii(object sender, EventArgs e)
        {
            //LocatiiFrm frm = new LocatiiFrm(this);
            //frm.MdiParent = mdiForm;
            ////frm.EnableSearch = false;
            //frm.Show();
        }

        public void Import(object sender, EventArgs e)
        {
            ImportFrm frm = new ImportFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void ParametrizareModul(object sender, EventArgs e)
        {
            FaresSetupFrm frm = new FaresSetupFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void CoduriCPV(object sender, EventArgs e)
        {
            //CPVFrm frm = new CPVFrm(this);
            //frm.MdiParent = mdiForm;
            //frm.Show();
        }

        public void Articole(object sender, EventArgs e)
        {
            ArticoleCardFrm frm = new ArticoleCardFrm(this,-1);
            frm.MdiParent = mdiForm;
            frm.Show();
        }
        
        public void CategoriiArticole(object sender, EventArgs e)
        {
            CategoriiArticoleFrm frm = new CategoriiArticoleFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void RaportCategoriiArticole(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(this,1);
            //frm.Text += "-" + "Centralizator pe categorii";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void RaportContabil(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(this, 3);
            //frm.Text += "-" + "Operatiuni Contabile";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void RaportFacturi(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(this, 4);
            //frm.Text += "-" + "Operatiuni Contabile";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void RaportFisaPartenerului(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(this, 6);
            //frm.Text += "-" + "Operatiuni Contabile";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void RaportOperatiuniIncasarePlata(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(this, 5);
            //frm.Text += "-" + "Operatiuni Contabile";
            frm.MdiParent = mdiForm;
            frm.Show();
        }


        public void RaportDocumente(object sender, EventArgs e)
        {
            OptiuniRapoarteFrm frm = new OptiuniRapoarteFrm(this,2);
            //frm.Text += "-" + "Lista Documente";
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Departamente(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.DepartamenteFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void Jurnale(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.JurnaleFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this,true }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void Semnaturi(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.SemnaturiFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }


        public void Judete(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;
            String numeClasa = "ERPForms.JudeteFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }
        public void Localitati(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.LocalitatiFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void UnitatiMasura(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.UnitatiMasuraFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void RaportJurnale(object sender, EventArgs e)
        {
            JurnaleFrm frm = new JurnaleFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        /*public static void Parametrizare(object sender, EventArgs e)
        {
            BalconSetupFrm frm = new BalconSetupFrm();
            frm.MdiParent = mdiForm;
            frm.EnableSearch = false;
            frm.Show();
        }
        public static void SeriiNumerice(object sender, EventArgs e)
        {
            SeriiNumericeRezumatFrm frm = new SeriiNumericeRezumatFrm();
            frm.MdiParent = mdiForm;
            frm.Show();
        }

    */
        public void Consultare_Arhiva(object sender, EventArgs e)
        {
            if (AnArhiva == String.Empty)
            {
                FrmMainMdi frm = mdiForm as FrmMainMdi;
                Assembly asm = frm.GetModule("erpforms");
                if (asm == null)
                    return;
                String numeClasa = "ERPForms.ConsultareArhivaFrm";
                Type mModule = asm.GetType(numeClasa);

                if (mModule != null)
                {
                    FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                       new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                    newFrm.MdiParent = frm;
                    newFrm.Show();
                }
            }
            else
            {
                ToolStripMenuItem mn_Consultare_Arhiva = null;
                ToolStripMenuItem mn_Parametrizare_Modul = null;

                mn_Consultare_Arhiva = FindMenuItem(menuMain, "Consultare Arhiva");
                mn_Parametrizare_Modul = FindMenuItem(menuMain, "Setari");

                AnArhiva = String.Empty;
                mn_Consultare_Arhiva.Text = "Consultare Arhiva";
                StudioForm.SetArhiva(AnArhiva);
                mn_Parametrizare_Modul.Visible = true;
            }

        }

        public void Tipuri_Departamente(object sender, EventArgs e)
        {

            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.TipDepartamentFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }


        }

        public void Tipuri_Documente(object sender, EventArgs e)
        {
            TipDocumenteFrm frm = new TipDocumenteFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Curs_Valutar(object sender, EventArgs e)
        {

            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.CursValutarFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void Productie(object sender, EventArgs e)
        {
            UrmarireComenziFrm frm = new UrmarireComenziFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Lista_Stocuri(object sender, EventArgs e)
        {
            OptiuniRapoarteStocuriFrm frm = new OptiuniRapoarteStocuriFrm(this, 1);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Lista_Rulaje(object sender, EventArgs e)
        {
            OptiuniRapoarteRulajeFrm frm = new OptiuniRapoarteRulajeFrm(this, 1);
            frm.MdiParent = mdiForm;
            frm.Show();            
        }

        public void Lista_FisaMagazie(object sender, EventArgs e)
        {
            OptiuniRapoarteFisaMagazieFrm frm = new OptiuniRapoarteFisaMagazieFrm(this, 1);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void TipProgrameSanatate(object sender, EventArgs e)
        {
            ProgrameSanatateFrm frm = new ProgrameSanatateFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }


    }
}
